﻿
using System;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Krupa.Pro.Web.Utility.Composite;

namespace Krupa.Pro.Web
{
    // Примечание: Инструкции по включению классического режима IIS6 или IIS7 
    // см. по ссылке http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            var version = Assembly.GetExecutingAssembly().GetName().Version;

            //include assembly version in static cachable resource path
            //avoids cache hits after application version update
            routes.MapRoute("Composite.Static.Js", String.Format("static/{0}/{{action}}.js",version), new { controller = "Js" });
            routes.MapRoute("Composite.Static.Css", String.Format("static/{0}/{{action}}.css", version), new { controller = "Css" });
            routes.MapRoute("Composite.Static.Js.Old", "static/{version}/{action}.js", new { controller = "Js" });
            routes.MapRoute("Composite.Static.Css.Old","static/{version}/{action}.css", new { controller = "Css" });

            routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            //Register your View Engine Here.

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorExtensionEngine());
        }
    }
}